﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShiXuLong.Model;
using ShiXuLong.Service;
using System.Web.Security;

namespace ShiXuLong.Web.Controllers
{
    public class LoginController : Controller
    {
        FrontDesk fd = new FrontDesk();
        // GET: Login
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult LoginView()
        {

            return View();
        }
        public ActionResult Login(string username, string password)
        {
            int UserId = 0;
            var res = fd.Login(username, password, out UserId);
            if (res)
            {

                FormsAuthentication.SetAuthCookie(username, true);
                MyConfig.UserID = UserId;
                return Json(new { msg = "登录成功", success = true });
            }
            else
            {


                return Json(new { msg = "登录失败", success = false });
            }

        }
        public ActionResult LogOut()
        {
            MyConfig.UserID = 0;
            FormsAuthentication.SignOut();
            return Json(new {success=true,msg="执行成功" });
        }

    }
}